﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using MvcEngine.Core;
using MvcEngine.Core.Extensions;
using MvcEngine.Core.Utils;
using MvcEngine.Mvc.Extensions;
using MvcEngine.Core.Helpers;
using MvcEngine.Mvc.ModelBinders;
using MvcEngine.Core.Base;
using MvcEngine.Gallery.Models;

namespace MvcEngine.Gallery.ModelBinders
{
    public class GalleryModelBinder : ModelBinderBase
    {
        public override object Bind(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            HttpRequestBase request = controllerContext.HttpContext.Request;
            GalleryData gallery = IoC.Resolve<GalleryData>();

            var modelState = controllerContext.Controller.ViewData.ModelState;
            gallery.ImagesPerPage = request.Form.Get("ImagesPerPage").ToInt();
            gallery.DefaultCategoryId = request.Form.Get("DefaultCategory").ToNullableGuid();
            Validate(gallery, controllerContext, new string[] { "Name" });
            return gallery;
        }
    }
}
